﻿using SIG.Model.Shipping;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;


namespace SIG.Model.Mapping
{
    public class DistrictMap : EntityTypeConfiguration<District>
    {
        public DistrictMap()
        {
            this.HasKey(p => p.Id);

            this.Property(p => p.Id)
                .HasColumnName("Id")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.ToTable("T_District");

            this.Property(p => p.Name).HasMaxLength(50).IsRequired();
            this.Property(p => p.CityId).IsRequired();
            this.Property(p => p.Sort).IsRequired();          

            this.HasRequired(p => p.City)
            .WithMany(h => h.Districts)
            .HasForeignKey(p => p.CityId); 
        }
    }
}
